<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <ul>
            <li v-for="(item,index) in arr" :key="index">{{item}} <button @click="del(index)">删除</button></li>
        </ul>
        <button @click="fn">生成</button>
    </div>
</body>
<script src="../vue.js"></script>
<script>
    const app = new Vue({
        el: '#app',
        data: {
            arr: [1, 3, 5]
        },
        methods: {
            fn() {
                console.log(parseInt(Math.random() * 20 + 1))
                this.arr.push(parseInt(Math.random() * 20 + 1))
            },
            del(index) {
                console.log(index)
                this.arr = this.arr.filter((item, idnex) => idnex !== index)
            }
        }
    })
</script>

</html>